'''
Created on May 4, 2011

@author: Miles
'''

from django.views.generic import list_detail
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.conf import settings
import unicodedata
from api import collector
import json

def search_products(request):
    if request.method == 'GET':
        args = dict(request.GET.items())

        q = unicodedata.normalize('NFKD', args['q']).encode('ascii','ignore')

        if not q.isdigit():
            params = {"string":q}
        else:
            params = {"isbn":str(q)}

        results = collector.search2(params)
        results = json.loads(results)  

    return render_to_response( "search_results.html", {'results':results, 'q':q},
            context_instance=RequestContext(request)
            )
